#include "lua_util.h"


float LuaStringKeyFloatValue( lua_State * s, int idx, std::string key )
{

	lua_getfield( s, idx, key.c_str() );
	float val = lua_tonumber( s, -1 );
	lua_pop( s, 1 );
		
	return val;
	
}
	
int LuaStringKeyIntValue( lua_State * s, int idx, std::string key )
{

	lua_getfield( s, idx, key.c_str() );
	int val = lua_tonumber( s, -1 );
	lua_pop( s, 1 );
		
	return val;

}

std::string LuaStringKeyStringValue( lua_State * s, int idx, std::string key )
{

	lua_getfield( s, idx, key.c_str() );
	std::string val = lua_tostring( s, -1 );
	lua_pop( s, 1 );
		
	return val;
	
}

//Don't forget to pop twice!
void LuaGetEntityTable( lua_State * s, int id )
{
	
	lua_getglobal( s, "EntDataTable" );
	
	lua_pushnumber( s, id );
	lua_gettable( s, -2 );
	
	if( LuaNil( s ) )
	{
		
		lua_pop( s, 1 );
		
		lua_pushnumber( s, id );
		lua_newtable( s );
		lua_settable( s, -3 );
		
		lua_pushnumber( s, id );
		lua_gettable( s, -2 );
		
	}
	
}